<template>
  <div class="campusInformation">
    <div class="top_img" :style="'background-image: url(' + topBg + ')'">
      <span>校 园 资 讯</span>
    </div>
    <div class="main">
      <div class="left">
        <div class="title">校园资讯</div>
      </div>
      <div class="right">
        <div class="title">
          <span>校园资讯</span>
          <span>
            <span @click="$router.push('/')">首页</span>>><span>校园资讯</span>
          </span>
        </div>
        <ul>
          <li
            v-for="(e, i) in initData"
            :key="i"
            @click="$router.push('/campus_information/details/' + e.id)"
          >
            <div class="col_title">
              <span>
                {{ e.title }}
              </span>
              <span>
                {{
                  $moment(parseInt(e.createdAt)).format("YYYY-MM-DD HH:mm:ss")
                }}
              </span>
            </div>
            <div class="col_content">
              {{ e.content }}
            </div>
          </li>
        </ul>
      </div>
    </div>
    <el-pagination
      style="text-align: center; margin-top: 24px"
      background
      layout="prev, pager, next"
      :total="total"
      @current-change="handleSizeChange"
      :page-size="query.pageSize"
    >
    </el-pagination>
  </div>
</template>
<script>
import { getNewsList } from "@/util/news.js";

export default {
  data() {
    return {
      topBg:
        "http://175.178.92.128:8087/campus_help_system/images/insidePages/20190910163919740.jpg",
      initData: [],
      total: 5,
      query: {
        key: {
          title: "",
        },
        pageSize: 5,
        pageNum: 1,
      },
    };
  },
  created() {
    this.getNewsList();
  },
  mounted() {},
  methods: {
    // 获取数据
    async getNewsList() {
      let { data: res } = await getNewsList(this.query);
      if (res.status != 2000) {
        return this.$message.error(res.msg);
      }
      this.initData = res.data.list;
      this.total = res.data.total;
    },
    // 分页
    handleSizeChange(e) {
      this.query.pageNum = e;
      this.getNewsList();
    },
  },
};
</script>
<style lang="less" scoped>
.campusInformation {
  padding-bottom: 50px;
  .top_img {
    height: 280px;
    background-repeat: no-repeat;
    background-size: auto 100%;
    background-position: center center;
    display: flex;
    align-items: center;
    justify-content: center;
    & > span {
      font-size: 48px;
      font-weight: 700;
      color: #fff;
    }
  }
  .main {
    width: 1200px;
    margin: 0 auto;
    padding-top: 50px;
    display: flex;
    .left {
      margin-right: 60px;
      .title {
        height: 50px;
        font-size: 18px;
        background: #0166b6;
        padding-left: 15px;
        width: 200px;
        line-height: 50px;
        color: #fff;
      }
    }
    .right {
      flex: 1;
      .title {
        justify-content: space-between;
        display: flex;
        padding: 12px 0;
        border-bottom: 1px solid #ddd;
        & > span:nth-child(1) {
          font-size: 24px;
          color: #333333;
          line-height: 24px;
          font-size: 700;
        }
        & > span:nth-child(2) {
          & > span:nth-child(1) {
            cursor: pointer;
            margin-right: 12px;
          }
          & > span:nth-child(2) {
            color: #0e3782;
            margin-left: 12px;
          }
        }
      }

      & > ul {
        & > li {
          cursor: pointer;
          padding: 18px 0;
          border-bottom: 1px solid #e5e5e5;
          .col_title {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 18px;
            & > span:nth-child(1) {
              line-height: 26px;
              font-size: 16px;
              color: #666666;
              width: 300px;
              white-space: nowrap; //在一行显示
              text-overflow: ellipsis; //多余用....显示
              overflow: hidden;
            }
            & > span:nth-child(2) {
              color: #aaa;
              font-size: 14px;
            }
          }
          .col_content {
            font-size: 14px;
            line-height: 1.6;
            color: #999999;
            text-overflow: -o-ellipsis-lastline;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 3;
            line-clamp: 3;
            -webkit-box-orient: vertical;
          }
        }
      }
    }
  }
}
</style>
